Numpy Statistical Analysis: Quick Start with mean, sum, and max Functions
This article introduces the usage methods of three commonly used statistical functions in NumPy: `mean` (average), `sum` (summation), and `max` (maximum). As a core tool for Python data analysis, NumPy provides efficient multidimensional arrays and statistical functions. All three functions support the `axis` parameter to control the calculation direction: `axis=0` calculates column-wise (vertically), `axis=1` calculates row-wise (horizontally), and if not specified, the overall value is computed. - **mean**: Computes the arithmetic mean of array elements. For a one-dimensional array, it returns the overall average; for a two-dimensional array, it can compute column-wise or row-wise averages. - **sum**: Computes the sum of array elements. Similar to `mean`, it specifies row or column summation via the `axis` parameter. - **max**: Finds the maximum value in the array, also supporting maximum value calculation across rows or columns. The article demonstrates basic usage with one-dimensional and two-dimensional array examples, and applies them to a practical case of student scores (3 students × 3 courses): calculating the average score per course, total score per student, and highest score. This verifies the practicality of the functions. It concludes that mastering these three functions and the `axis` parameter is fundamental for data analysis, laying the groundwork for subsequent complex analyses.
Read More